<form class="layui-form detail-seller-form"  action="" style="padding-top:10px">
    <input type="hidden" name="id" id="id" value="{$id}">

    <div class="layui-form-item" style="margin-bottom:5px"> 
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">学号：</label>
            <div class="layui-input-inline" id="xh_box">
                <input type="text" id="xh" name="xh" class="layui-input" value="" placeholder="请输入学号" ></input>
            </div>
        </div>  
        <div class="layui-inline">
            <label class="layui-form-label seller-inline-2">姓名：</label>
            <div class="layui-input-inline" id="xh_box">
                <input type="text" id="xm" name="xm" class="layui-input" value="" placeholder="请输入姓名" ></input>
            </div>
        </div>  
        <div class="layui-inline">
            <button id="rel_get_save" class="layui-btn layui-btn-sm" lay-submit lay-filter="detailsearch"><i class="iconfont icon-chaxun"></i>查询</button>
            <button id="exportBtn" class="layui-btn layui-btn-sm layui-btn-disabled" lay-submit lay-filter="export-studentDetail"><i
                class="iconfont icon-clouddownload" style="font-size: 20px !important;" disabled></i>导出</button> 
        </div>
    </div>
</form>

<div class="table-body" style="margin-top:0px">
    <table id="extraDetailTable" lay-filter="extraDetailTable"></table>
</div>

<div id="exportstudentDetail" style="display: none;">
    <form class="layui-form export-form" action="">
        <div class="layui-form-item">
            <div class="layui-margin-10">
                <blockquote class="layui-elem-quote layui-text">
                    请先筛选要导出的学生，默认导出全部
                </blockquote>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">任务名称：</label>
                <input type="text" name="taskname" lay-verify="title" style="width:200px;" placeholder="请输入任务名称"
                    autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>

<script>
    var mgrMobile = '';
    layui.use(['table','form','layer','laydate'],function(){
        var layer = layui.layer, table = layui.table,form = layui.form;

        // 定义变量保存当前页面和当前页面数据条数
        var currPage; 
        var dataNum;
        //执行渲染
        table.render({
            elem: '#extraDetailTable', //指定原始表格元素选择器（推荐id选择器）
            height: '330',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            id:'extraDetailTable',
            url: "{:url('BookDraw/getBookExtraDrawStudentDetailList')}?id={$id}",
            cols: [[ //标题栏
                { type:'numbers'},
                { field: 'id', title: 'ID', hide:true},
                { field: 'xh', sort: true, title: '学号', width: 120, align: 'center' },
                { field: 'xm', sort: true, title: '姓名', width: 160, align: 'center' },
                { field: 'zymc', sort: true, title: '专业', width: 160, align: 'center' },
                { field: 'bjmc', sort: true, title: '班级', width: 160, align: 'center' },
                {
                    field: 'operating', title: '操作', width: 80, align: 'center', templet: function (data) {
                        var html = '';
                        html += '<a class="layui-btn layui-btn-xs layui-btn-danger" name="del" id="' + data.id + '" lay-event="del">删除</a>';
                        return html;
                    }
                },
            ]], //设置表头
            done: function(res, curr, count){
                // 判断加载结果数量是否大于0
                if(count>0){
                    $("#exportBtn").removeClass("layui-btn-disabled");
                    $('#exportBtn').removeAttr("disabled");
                } else {
                    $('#exportBtn').addClass("layui-btn-disabled");
                    $('#exportBtn').attr("disabled", true);
                }
                // 给变量赋值 
                dataNum = res.data.length;
                currPage = curr;
            }
            //,…… //更多参数参考右侧目录：基本参数选项
        });

        // 查询
        form.on('submit(detailsearch)', function (data) {
            table.reload('extraDetailTable', {
                where: data.field,
                page: {curr: 1},
                url: "{:url('BookDraw/getBookExtraDrawStudentDetailList')}?id={$id}",
            });

            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
 
        // 监听工具条
        table.on('tool(extraDetailTable)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            
            var extraId = $("#id").val();
            var id = $(this).attr('id');

            if(layEvent === 'del'){ // 修改
                $("a[name='del']").addClass("layui-btn-disabled");
                $("a[name='del']").attr("disabled", true);
                
                layer.confirm('您确定删除此学生明细吗？', {
                    btn: ['确认', '取消'], //按钮
                    cancel:function(index, layero){
                        $("a[name='del']").removeClass("layui-btn-disabled");
                        $("a[name='del']").removeAttr("disabled");
                    }
                }, function () {
                    JsPost("{:url('BookDraw/bookextradrawbookdetaildel')}", {extraId:extraId, id:id}, function (res) {
                        $("a[name='del']").removeClass("layui-btn-disabled");
                        $("a[name='del']").removeAttr("disabled");
                        
                        //删除逻辑中判断只有一条数据时应该刷新前一页信息
                        layer.msg(res.msg);
                        if(res.status){
                            if(dataNum == 1){
                                currPage = currPage - 1;
                            }

                            table.reload('extraDetailTable', {
                                page: {
                                    curr: currPage
                                }
                            });
                            parent.layui.admin.events.refreshTab('/manage/book_draw/bookextradrawindex.html', 'bookextradrawTable');
                            return false;
                        }
                    });
                }, function () {
                    $("a[name='del']").removeClass("layui-btn-disabled");
                    $("a[name='del']").removeAttr("disabled");
                    layer.close(1);
                }); 
            }
        });
        //非计划发放学生信息导出
        layui.form.on('submit(export-studentDetail)', function (data) {
            layer.open({
                type: 1,
                title: '非计划发放学生明细导出',
                area: ['400px', '248px'], //宽高
                btn: ['确定', '取消'],
                content: $("#exportstudentDetail").html(),
                success: function () {
                    $(':focus').blur();
                    this.enterEsc = function(event){
                        if(event.keyCode === 13){
                            if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                                $(".layui-layer-btn0").addClass("layui-btn-disabled");

                                //判断是否有选中
                                var filter = $(".detail-seller-form").serialize();
                                $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                                var data = $(".export-form:last").serializeArray();
                                data.push({ 'name': 'model', 'value': 'BookExtraDrawStudentDetail' });

                                if($.trim(data[0]['value']) == '') {
                                    layer.msg('请填写任务名称！', { time: 1300 });
                                    $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    return false;
                                }

                                JsPost("{:url('Ietask/export')}", data, function (res) {
                                        layer.msg(res.msg, { time: 1500 }, function () {
                                            if (res.status) {
                                                layer.closeAll();
                                                //执行跳转
                                                var topLayui = parent === self ? layui : top.layui;
                                                topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                            } else {
                                                $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                            }
                                        });
                                    }
                                );
                            }
                            return false; //阻止系统默认回车事件
                        }
                    };
                    $(document).on('keydown', this.enterEsc);	//监听键盘事件，关闭层
                },
                yes: function () {
                    if(!$(".layui-layer-btn0").hasClass("layui-btn-disabled")){
                        $(".layui-layer-btn0").addClass("layui-btn-disabled");

                        //判断是否有选中
                        var filter = $(".detail-seller-form").serialize();
                        $(".export-form:last").append("<input type='hidden' name='filter' value='" + filter + "'>");
                        var data = $(".export-form:last").serializeArray();
                        if($.trim(data[0]['value']) == '') {
                            layer.msg('请填写任务名称！', { time: 1300 });
                            $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                            return false;
                        }

                        data.push({ 'name': 'model', 'value': 'BookExtraDrawStudentDetail' });
                        JsPost("{:url('Ietask/export')}", data, function (res) {
                                layer.msg(res.msg, { time: 1500 }, function () {
                                    if (res.status) {
                                        layer.closeAll();
                                        //执行跳转
                                        var topLayui = parent === self ? layui : top.layui;
                                        topLayui.index.openTabsPage('/manage/ietask/index.html', '导入导出');
                                    } else {
                                        $(".layui-layer-btn0").removeClass("layui-btn-disabled");
                                    }
                                });
                            }
                        );
                    }
                }, btn2: function () {
                    layer.closeAll();
                }, end: function(){
                    $(document).off('keydown', this.enterEsc);	        //解除键盘关闭事件
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        form.render();
    })
</script>